<?php
/**
物业端用户操作
 */
namespace App\Http\Controllers\Tenement;

use App\Common\json;
use App\Common\SmsClient;
use App\Http\Controllers\Controller;
use App\Libraries\UploadApp;
use App\Libraries\upload;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;


class UserController extends Controller{


    public function login(Request $request){
        if($request -> isMethod('post')){

            $phone     = $request ->input('phone');
            $pass      = $request ->input('pass');
            $data     = DB::table('work')
                ->leftjoin('village','work.work_village','=','village.village_id')
                ->where('work_phone',$phone)
                ->where('work_password',$pass)
                ->get();
            if($data  == true){
                foreach ($data as $value){
                    $key   = array(
                        'work_id'=>$value->work_id,
                        'work_head'   =>$value->work_head,
                        'work_nickname'    =>$value->work_nickname,
                        'work_phone'=>$value->work_phone,
                        'village_id'      =>$value ->village_id,
                        'village_name'    =>$value ->village_name,
                        'village_enterprise' => $value ->village_enterprise,
                        'work_notice'           => $value ->is_notice,
                        'work_repair'           => $value ->is_repair,
                        'work_complaints'       => $value ->is_complaints,
                        'work_pay'               => $value ->is_pay,
                        'work_user'             => $value ->is_user,
                        'work_visitor'          => $value ->is_visitor,
                        'work_release'          => $value ->is_release,
                        'work_staff'            => $value ->is_staff
                    );
                }
                return json::json('success','恭喜您登录成功',$key);
            }else{
                return json::json('failure','由于网络或者不正当原因失败','');
            }
        }else{
            return json::json('101','提交方式错误','');
        }
    }

    public function Updatepersonal(Request $request){
        if($request ->isMethod('post')){
            $property_id      = $request ->input('work_id');
            $property_head    = $request ->input('head');
            $property_nickname  = $request ->input('nickname');
            $data     = DB::table('work')
                ->where('work_id',$property_id)
                ->update([
                    'work_head'  =>$property_head,
                    'work_nickname' => $property_nickname
                ]);
            if($data == true){
                return json::json('success','恭喜您修改成功','');
            }else{
                return json::json('failure','由于网络或者不正当原因失败','');
            }




        }
    }

}